package com.qf.strategy.service.Impl;

import com.qf.strategy.feign.CacheService;
import com.qf.strategy.service.FilterChain;
import com.qf.strategy.service.QueueService;
import com.qianfeng.smsplatform.common.constants.CacheConstants;
import com.qianfeng.smsplatform.common.constants.StrategyConstants;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.zip.DataFormatException;

/**
 * @author 徐老板
 * @date 2020/2/27   17:49
 */
@Service
public class SmsBlackFilter implements FilterChain {
    private static final Logger LOGGER = LoggerFactory.getLogger(SmsBlackFilter.class);
    @Autowired
    private CacheService cacheService;
    @Resource
    private QueueService queueService;

    @Override
    public boolean dealSms(Standard_Submit submit) throws DataFormatException {
    LOGGER.error("SmsBlackFilter方法执行了:{}",submit);

        String result = cacheService.get(CacheConstants.CACHE_PREFIX_BLACK + submit.getDestMobile());
        if (StringUtils.isEmpty(result)) {
            //代表没有这个 key 就说明不是黑名单
            LOGGER.error("当前手机号:{}不在黑名单中",submit.getDestMobile());
            return true;
        }else{
            //统计数据
            LOGGER.error("当前手机号:{}是黑名单",submit.getDestMobile());
            //TODO 发送数据到 es来进行统计
            queueService.sendSearchMQ(submit, StrategyConstants.STRATEGY_ERROR_BLACK);
            queueService.pushInterface(submit, StrategyConstants.STRATEGY_ERROR_BLACK);

        }
        return false;

    }

}
